package com.dimanche.library_base.widget.dialog;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.dimanche.library_base.R;
import com.dimanche.library_base.baseui.BaseAutoCancelDialog;


/**
 * author : Dimanche
 * date   : 2020/9/7 16:52
 * desc   : 上下结构的居中提示框
 * version: 1.0
 */
public class TipAutoCancelDialog extends BaseAutoCancelDialog {
    private final Context mContext;
    private ImageView imageView;
    private TextView tv;
    private LinearLayout linearLayout;
    private final String msg;
    private final Drawable drawable;


    public TipAutoCancelDialog(@NonNull Context context, String msg, Drawable drawable) {
        super(context);
        this.mContext = context;
        this.msg = msg;
        this.drawable = drawable;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }


    private void initView() {
        linearLayout = new LinearLayout(mContext);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT
        );
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        linearLayout.setPadding(0, 15, 0, 0);
        imageView = new ImageView(mContext);
        imageView.setImageDrawable(drawable);
        linearLayout.addView(imageView);
        LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        tv = new TextView(mContext);
        tv.setGravity(Gravity.CENTER);
        tv.setTextSize(30);
        tv.setTextColor(mContext.getResources().getColor(R.color.black));
        tv.setText(msg);
        linearLayout.addView(tv, tvParams);
        addContentView(linearLayout, params);
    }


}
